module.exports = () => {
  return async function errorHandle(ctx, next) {
    console.log(ctx.request.url)
    try {
      await next()
    } catch (error) {
      ctx.app.emit('error', error, ctx)

      const status = error.status || 500
      const err = status === 500 && ctx.app.config.env === 'prod' ? '网络错误' : error.message

      ctx.body = {
        message: err,
        status,
        data: []
      }
    }
  }
}